﻿@model MvcCmsSocial.Models.ViewData.SocialModel
@{
    int start = 0;
    int end = 0;
    int pageBuffer = 0;
    if (Model._SocialMessages.GetPagination.TotalPages <= pageBuffer)
    {
        start = 1;
        end = Model._SocialMessages.GetPagination.TotalPages;
    }
    else
    {
        start = Math.Max(Model._SocialMessages.GetPagination.PageNumber - pageBuffer, 1);
        end = Math.Min(Model._SocialMessages.GetPagination.PageNumber + pageBuffer, Model._SocialMessages.GetPagination.TotalPages);
    }    
}
<div class="pager">
    @if (Model._SocialMessages.GetPagination.TotalItems > Model._SocialMessages.GetPagination.PageSize)
    {
        if (Model._SocialMessages.GetPagination.PageNumber > 1)
        {
            <a class="cap" href="@Model._User.UserName.ToProfileLink()/page@(Model._SocialMessages.GetPagination.PageNumber - 1)" rel="prev">Previous</a><text>&nbsp;</text>
        }
        else
        { 	
            <text><a class="cap disabled" rel="prev">Previous</a>&nbsp;</text>
        }
        if (start > 1)
        { 
	        <a href="@Model._User.UserName.ToProfileLink()/page@Model._SocialMessages.GetPagination.PageNumber">1</a><text>&nbsp;</text>
            if (start > 2)
            { 
                <span>...</span>
            }
        }
        for (int i = start; i <= end; i++)
        {
            if (Model._SocialMessages.GetPagination.PageNumber == i)
            {
	            <a class="selected" rel="self">@i</a><text>&nbsp;</text>
            }
            else
            {
	            <a href="@Model._User.UserName.ToProfileLink()/page@(Model._SocialMessages.GetPagination.PageNumber - i)">@i.ToString()</a><text>&nbsp;</text>
            }
        }
        if (end < Model._SocialMessages.GetPagination.TotalPages)
        {
            if (end < Model._SocialMessages.GetPagination.TotalPages - 1)
            { 
    	        <span>...</span>
            } 
	        <a href="@Model._User.UserName.ToProfileLink()/page@(Model._SocialMessages.GetPagination.TotalPages)">@Model._SocialMessages.GetPagination.TotalPages</a><text>&nbsp;</text>
        }

        if (ViewData.Model._SocialMessages.GetPagination.PageNumber < ViewData.Model._SocialMessages.GetPagination.TotalPages)
        { 
    	    <a class="cap" href="@Model._User.UserName.ToProfileLink()/page@(Model._SocialMessages.GetPagination.PageNumber + 1)" rel="next">Next</a><text>&nbsp;</text>
        }
        else
        {
	        <a class="cap disabled" rel="next">Next</a><text>&nbsp;</text>
        }                  
    }
</div>
